module zysx {
	export class Https {
        //static URL = "http://192.168.1.150/api";
        static URL = "";
        //获取数据 get方式
        public static getRequest(url: string,params: any = null,callback?: Function,target?:any){
            //定义变量
            let sendParam = "";
            let jsonObj = params;
            if(params) {
                for(let key in params){
                    if(!sendParam)sendParam +="?"+key+"="+params[key];
                    else sendParam +="&"+key+"="+params[key];
                }
            }
            
            var request = new egret.HttpRequest();
            request.addEventListener(egret.Event.COMPLETE,(e:egret.Event)=>{
                var response: any = JSON.parse(request.response);
                if(callback) callback.call(target,response);
            },this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR,(e:egret.Event)=>{
                //alert(JSON.stringify(request.response))
            },this);
            request.responseType = egret.HttpResponseType.TEXT;
            request.setRequestHeader("content-type","application/json");
            request.withCredentials = false;
            request.open(this.URL+url+sendParam,egret.HttpMethod.GET);
            request.send();
        }
        //获取数据 post方式
        public static postRequest(url: string,params: any = null,callback?: Function,target?:any){
            //定义变量
            var request = new egret.HttpRequest();
            request.addEventListener(egret.Event.COMPLETE,(e:egret.Event)=>{
                var response: any = JSON.parse(request.response);
                if(callback) callback.call(target,response);
            },this);
            request.responseType = egret.HttpResponseType.TEXT;
            request.setRequestHeader("content-type","application/x-www-form-urlencoded");
            request.withCredentials = false;
            request.open(this.URL+url,egret.HttpMethod.POST);
            let sendParam = "";
            if(params) {
                for(let key in params){
                    if(!sendParam)sendParam +=key+"="+params[key];
                    else sendParam +="&"+key+"="+params[key];
                }
            }
            request.send(sendParam);  // {userName:"dondogn1"}
        }

		/** 获取md5签名 */
		public static getMd5Sign(infoArr:Array<any>):string{
			let arr = infoArr.sort();
			let paramsStr = "";
			for (let i = 0; i < arr.length; i++) {
				paramsStr += arr[i];
			}
			return "" // Md5Util.ins.hex_md5(paramsStr += GameConfig.ins.sessionId + GameConfig.ins.SIGN_FESH_KEY);
		}
    }
}